{include file="index/header"}
<body>
<div class="fly-panel fly-panel-user">
  <div class="tpt-admin">
    <div class="tpt-btn" style="float: left;margin: 0 20px 0 0">
      <a href="{:url('member/add')}" class="layui-btn"><i class="layui-icon">&#xe608;</i> 添加会员</a>
    </div>
    <div style="float: left;">
      <form class="layui-form" action="" method="get">
        <input placeholder="输入关键字" name="ks" value="<?php echo input('ks');?>" type="text" class="layui-input" style="float: left;margin-right: 10px;width: 240px;">
        <button class="layui-btn" style="float: left;" value="查询" type="submit">查询</button>
      </form>
    </div>
    <form class="layui-form">
      <table width="100%">
        <tr>
          <th width="3%" align="center"><input type="checkbox" name="checkAll" lay-filter="checkAll"></th>
          <th width="5%" align="center">会员ID</th>
          <th width="10%" align="center">会员昵称</th>
          <th width="10%" align="center">注册IP</th>
          <th width="10%" align="center">积分</th>
          <th width="5%" align="center">头像</th>
          <th width="10%" align="center">邮箱</th>
          <th width="5%" align="center">会员等级</th>
          <th width="10%" align="center">注册时间</th>
          <th width="5%" align="center">验证</th>
          <th width="10%" align="center">基本操作</th>
        </tr>
        {volist name="MemberList" id="vo"}
        <tr>
          <td align="center"><input type="checkbox" name="ids[{$vo.userid}]" lay-filter="checkOne" value="{$vo.userid}"></td>
          <td align="center">{$vo.userid}</td>
          <td align="center">{$vo.username}</td>
          <td align="center">{$vo.userip}</td>
          <td align="center">{$vo.point}</td>
          <td align="center">{if condition="$vo['userhead'] neq ''"}<img src="__ROOT__{$vo.userhead}" height="30">{else /}暂无图片{/if}</td>
          <td align="center">{$vo.usermail}</td>
          <td align="center">{if condition="$vo['grades'] eq 1"}管理员{else /}注册会员{/if}</td>
          <td align="center">{$vo.regtime|date="Y-m-d",###}</td>
          <td align="center">
            <a change="{$vo.userid}" onclick="changestatus(this);" {if condition="$vo['status'] eq 1"}class="layui-unselect layui-form-switch"{else /}class="layui-unselect layui-form-switch layui-form-onswitch"{/if}><em>禁用</em><i></i>
            </a>
          </td>
          <td align="center">
            <a class="layui-btn layui-btn-mini layui-btn-warm" href="{:url('member/edit',array('id'=>$vo['userid']))}">修改</a> <a class="layui-btn layui-btn-mini layui-btn-danger del_btn" member-id="{$vo.userid}" title="删除" nickname="{$vo.username}">删除</a>
          </td>
        </tr>
        {/volist}
      </table>
      <div class="layui-form-item">
        <div style="margin-top: 20px;float: left;">
          <button class="layui-btn" lay-submit lay-filter="delete">删除选中</button>
        </div>
        <div class="pages" style="float: right;">{$MemberList->render()}</div>
      </div>
    </form>
  </div>
</div>
{include file="index_footer"}
<script type="text/javascript">
function changestatus(o){
  var change=$(o).attr("change");
  $.ajax({
    type:"post",
    dataType:"json",
    data:{change:change},
    url:"{:url('member/changestatus')}",
    success:function(data){
      if(data == 1){
        $(o).attr("class","layui-unselect layui-form-switch layui-form-onswitch");
        }else{
        $(o).attr("class","layui-unselect layui-form-switch");
        }
    }
  });
}
</script>
<script type="text/javascript">
layui.use('form',function(){
  var form = layui.form()
  ,jq = layui.jquery;

  jq('.del_btn').click(function(){
    var name = jq(this).attr('nickname');
    var id = jq(this).attr('member-id');
    layer.confirm('确定删除【'+name+'】?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      jq.post('{:url("member/dels")}',{'id':id},function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else{
          layer.close(loading);
          layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
        }
      });
    });
  });

  form.on('checkbox(checkAll)', function(data){
    if(data.elem.checked){
      jq("input[type='checkbox']").prop('checked',true);
    }else{
      jq("input[type='checkbox']").prop('checked',false);
    }
    form.render('checkbox');
  });  

  form.on('checkbox(checkOne)', function(data){
    var is_check = true;
    if(data.elem.checked){
      jq("input[lay-filter='checkOne']").each(function(){
        if(!jq(this).prop('checked')){ is_check = false; }
      });
      if(is_check){
        jq("input[lay-filter='checkAll']").prop('checked',true);
      }
    }else{
      jq("input[lay-filter='checkAll']").prop('checked',false);
    } 
    form.render('checkbox');
  });

  form.on('submit(delete)', function(data){
    var is_check = false;
    jq("input[lay-filter='checkOne']").each(function(){
      if(jq(this).prop('checked')){ is_check = true; }
    });
    if(!is_check){
      layer.msg('请选择数据', {icon: 2,anim: 6,time: 1000});
      return false;
    }
    layer.confirm('确定批量删除?', function(index){
      loading = layer.load(2, {
        shade: [0.2,'#000']
      });
      var param = data.field;
      jq.post('{:url("member/delss")}',param,function(data){
        if(data.code == 200){
          layer.close(loading);
          layer.msg(data.msg, {icon: 1, time: 1000}, function(){
            location.reload();
          });
        }else{
          layer.close(loading);
          layer.msg(data.msg, {icon: 2,anim: 6, time: 1000});
        }
      });
    });
    return false;
  });

})
</script>
</body>
</html>